package com.zygh.lz.service.impl;

import com.zygh.lz.dao.XrelationMapper;
import com.zygh.lz.entity.Xrelation;
import com.zygh.lz.service.XrelationService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class XrelationServiceImpl implements XrelationService {

    @Resource
    private XrelationMapper xrelationMapper;

    @Override
    public ResultBean insertXrelation(Xrelation xrelation) {
        int insert = 0;
        Integer[] userId = xrelation.getUserId();
        for (Integer user : userId) {
            xrelation.setStaffId(user);
            insert = xrelationMapper.insertSelective(xrelation);
        }
        return ResultUtil.execOp(insert, "新增");
    }

    @Override
    public ResultBean updateXrelation(Xrelation xrelation) {
        Xrelation xrealationByid = xrelationMapper.findXrealationByid(xrelation.getStaffId(), xrelation.getXareaId());
        xrelation.setId(xrealationByid.getId());
        return ResultUtil.execOp(xrelationMapper.updateByPrimaryKeySelective(xrelation), "修改");
    }

    @Override
    public ResultBean deleteXrelatonByid(Integer staffId, Integer xareaId) {
        return ResultUtil.execOp(xrelationMapper.deleteById(staffId, xareaId), "删除");
    }

    @Override
    public ResultBean deleteXrelatonByXareaid(Integer xareaId) {
        return ResultUtil.execOp(xrelationMapper.deleteByXareaid(xareaId), "删除");
    }


}
